﻿package  {
	// These lines make differant 'pieces' available in your code.
	import flash.display.*; // To extend this class
	import flash.events.Event; // To work out when a frame is entered.
	import org.papervision3d.view.Viewport3D; // We need a viewport
	import org.papervision3d.cameras.*; // Import all types of camera
	import org.papervision3d.scenes.Scene3D; // We'll need at least one scene
	import org.papervision3d.render.BasicRenderEngine; // And we need a renderer
	//import org.papervision3d.core.math.Number3D.; //I need to rotate stuff
	//public function rotateY(angle:Number):voidParameters  angle:Number 


	
	
	public class PaperBase extends MovieClip { //Must be "extends Sprite"
	   public var viewport:Viewport3D; // The Viewport
	   public var renderer:BasicRenderEngine; // Rendering engine
	   // -- Scenes -- //
	   public var default_scene:Scene3D; // A Scene
	   // -- Cameras --//
	   public var default_camera:Camera3D; // A Camera
	   public var cam2:Camera3D; //A FRUGGIN SECOND CAMRA
	   public var view2:Viewport3D;
	   
	   public function init(vpWidth:Number = 800, vpHeight:Number = 600):void {
		 initPapervision(vpWidth, vpHeight); // Initialise papervision
		 init3d(); // Initialise the 3d stuff..
		 init2d(); // Initialise the interface..
		 initEvents(); // Set up any event listeners..
	   }
	   protected function initPapervision(vpWidth:Number, vpHeight:Number):void {
		 // Here is where we initialise everything we need to
		 // render a papervision scene.
		 viewport = new Viewport3D(vpWidth, vpHeight);
		 view2 = new Viewport3D();
		 //viewport.x = 0;
		 // The viewport is the object added to the flash scene.
		 // You 'look at' the papervision scene through the viewport
		 // window, which is placed on the flash stage.
		 addChild(viewport); // Add the viewport to the stage.
		 // Initialise the rendering engine.
		 renderer = new BasicRenderEngine();
		 // -- Initialise the Scenes -- //
		 default_scene = new Scene3D();
		 // -- Initialise the Cameras -- //
		 default_camera = new Camera3D(); 
		 cam2 = new Camera3D();
		 //default_camera = new DebugCamera3D(viewport); 
		 // The argument passed to the camera
		 // is the object that it should look at. I've passed the scene object
		 // so that the camera is always pointing at the centre of the scene.
	   }
	   protected function init3d():void {
		 // This function should hold all of the stages needed
		 // to initialise everything used for papervision.
		 // Models, materials, cameras etc.
	   }
	   protected function init2d():void {
		 // This function should create all of the 2d items
		 // that will be overlayed on your papervision project.
		 // User interfaces, Heads up displays etc.
	   }
	   protected function initEvents():void {
		 // This function makes the onFrame function get called for
		 // every frame.
		 addEventListener(Event.ENTER_FRAME, onEnterFrame);
		 // This line of code makes the onEnterFrame function get
		 // called when every frame is entered.
	   }
	   protected function processFrame():void {
		 // Process any movement or animation here.
	   }
	   protected function onEnterFrame( ThisEvent:Event ):void {
		 //We need to render the scene and update anything here.
		 processFrame();
		 renderer.renderScene(default_scene, default_camera, viewport);
		 renderer.renderScene(default_scene, cam2, view2);
	   }
	}
}